package 双指针.查找总价格为目标值的两个商品;

import java.util.Arrays;

public class SearchTwo {
    public static void main(String[] args) {
        Solution so = new Solution();
        int[] arr = {3, 9, 12, 15};
        int[] rel = so.twoSum(arr, 18);
        System.out.println(Arrays.toString(rel));
    }
}
class Solution {
    public int[] twoSum(int[] price, int target) {
        int[] temp = new int[2];
        int left = 0,right = price.length-1;
        while(left<right){
            if(price[left]+price[right] > target){
                right--;
            }else if(price[left]+price[right] < target){
                left++;
            }else{
                temp[0] = price[left];
                temp[1] = price[right];
                return temp;
            }
        }
        return temp;
    }
}